#!/bin/bash
echo "Direct compilation with MSYS2 UCRT64..."
echo

# 检查环境
if [[ ! -f "/etc/msys2-release" ]]; then
    echo "错误: 请在 MSYS2 UCRT64 环境中运行"
    exit 1
fi

# 检查依赖
if ! pkg-config --exists wxwidgets; then
    echo "请先安装 wxWidgets:"
    echo "pacman -S mingw-w64-ucrt-x86_64-wxWidgets"
    exit 1
fi

# 获取编译标志
WX_CFLAGS=$(pkg-config --cflags wxwidgets)
WX_LIBS=$(pkg-config --libs wxwidgets)

echo "编译标志: $WX_CFLAGS"
echo "链接库: $WX_LIBS"
echo

# 编译
echo "开始编译..."
g++ -std=c++11 -O2 -Wall -Wextra \
    $WX_CFLAGS \
    main_unified.cpp workspace_parser.cpp \
    $WX_LIBS \
    -o cbp2make_ai.exe

if [ $? -eq 0 ]; then
    echo
    echo "编译成功!"
    echo "可执行文件: cbp2make_ai.exe"
    ls -la cbp2make_ai.exe
else
    echo
    echo "编译失败!"
    exit 1
fi
echo
